<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Jquery完成全选 全取消 反选</title>
<script type="text/javascript" src="../jquery-3.1.1.min.js"></script>
<script type="text/javascript">
	$(function(){
		$("#div1 input:eq(0)").click(function(){
			$("#div2>input").attr("checked",true);
		});
		$("#div1 input:eq(1)").click(function(){
			$("#div2>input").attr("checked",false);
		});
		$("#div1 input:eq(2)").click(function(){
			$("#div2>input").each(function(){
				$(this).attr("checked",!$("#div2>input").attr("checked"));
			});
		});
	})
</script>
</head>
<body>
<div id="div1">
	<input type="button" value="全选">
	<input type="button" value="全取消">
	<input type="button" value="反选">
</div>
<div id="div2">
		请选择：
		<input type="checkbox" name="hobby" value="study" checked>学习
		<input type="checkbox" name="hobby" value="swiming">游泳
		<input type="checkbox" name="hobby" value="running">跑步
		<input type="checkbox" name="hobby" value="music">听音乐
		<input type="checkbox" name="hobby" value="game">玩游戏
</div>
</body>
</html>